from django.db import models


class Student(models.Model):
    name = models.CharField(max_length=20)
    gender = models.IntegerField(default=1)
    age = models.IntegerField()
    birth = models.DateTimeField()
    cellphone = models.CharField(max_length=20, null=True)

    def __str__(self):
        fmt = '\n\nName: %s\nAge: %s\nBirth: %s\nGender: %s\nPhone: %s\nPK: %s'
        return fmt % (self.name, self.age, self.birth.strftime('%F %T'),
                      self.gender, self.cellphone, self.pk)

    def __repr__(self):
        return self.__str__()


class Father(models.Model):
    name = models.CharField(max_length=20)
    phone = models.CharField(max_length=11)

    def __repr__(self):
        return self.name


class Child(models.Model):
    name = models.CharField(max_length=20)
    phone = models.CharField(max_length=11)
    father = models.ForeignKey(Father, on_delete=models.SET_NULL, null=True)

    def __repr__(self):
        return self.name


class Tag(models.Model):
    desc = models.CharField(max_length=128)

    def __repr__(self):
        return self.desc


class Article(models.Model):
    title = models.CharField(max_length=128)
    tag = models.ManyToManyField(Tag)

    def __repr__(self):
        return self.title


class Private(models.Model):
    keyid = models.CharField(max_length=128)
    public = models.OneToOneField('Public', null=True, related_name='public_key')

    def __repr__(self):
        return self.keyid


class Public(models.Model):
    keyid = models.CharField(max_length=128)
    private = models.OneToOneField('Private', null=True, related_name='private_key')

    def __repr__(self):
        return self.keyid


class M(models.Model):
    desc = models.CharField(max_length=10)
    time1 = models.DateTimeField(auto_now=True)
    time2 = models.DateTimeField(auto_now_add=True)
